home *** CD-ROM | disk | FTP | other *** search
- Path: kryten.awinc.com!news
- From: jenna.design@awinc.com (jenna design)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: How to the size of a file in C ?
- Date: 9 Feb 1996 16:18:56 GMT
- Organization: A & W Internet Inc.
- Message-ID: <4ffs5g$a71@kryten.awinc.com>
- References: <4ffeqa$pjh@brtph500.bnr.ca>
- NNTP-Posting-Host: pme004.awinc.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4ffeqa$pjh@brtph500.bnr.ca>, gilbertb@bnr.ca says...
- >
- >How do I get the size of a file in C UNIX-based? I tried sizeof <file>, but
- >that only returns the size of the object called "<file>" and not the data.
- >I know about filelength(), also, but that is DOS, Windows, and OS/2.
- >
- >Can someone help me? Post a reply, my email is corrupted.
- >--
- >Gilbert Banks
- >
-
- Try this function Gilbert.
-
- /*************************************************
- * This function determines the size of a file
- * Returns a long. Cast if you need to.
- * A return of 0 means failure else it returns number
- * of bytes read.
- * Your code should provide a error handling routine
- * if 0 is returned to the calling function.
- * Calling function must pass a pointer to \path\filename
- * details of the file.
- *
- */
- #include <stdio.h>
-
- long GetFileSize (char *ptr_fName)
- {
- FILE *fp;
- long f_size;
-
- if((fp = fopen(ptr_fName,"r"))==NULL)
- return 0;
-
- fseek(fp, 0L, SEEK_END);
- f_size = ftell(fp);
-
- fclose(fp);
-
- return (f_size);
- }
-
- /* Good day */
-
-